package cn.ly.core.thread.dielock;

public class Thread1 extends Thread{
	private LockObjA obja;
	private LockObjB objb;
	
	public Thread1(LockObjA a,LockObjB b){
		this.obja = a;
		this.objb = b;
	}
	
	
	public void run(){
		synchronized (obja) {
			System.out.println("--thread1:in synchronized obja block--");
			try {
				Thread.sleep(1000*3);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			synchronized (objb) {
				System.out.println("--thread1:in synchronized objb block--");
			}
		}
	}
}

class Thread2 extends Thread{
	private LockObjA obja;
	private LockObjB objb;
	
	public Thread2(LockObjA a,LockObjB b){
		this.obja = a;
		this.objb = b;
	}
	
	public void run(){
		synchronized (objb) {
			System.out.println("--thread2:in synchronized objb block--");
			try {
				Thread.sleep(1000*3);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			synchronized (obja) {
				System.out.println("--thread2:in synchronized obja block--");
			}
		}
	}
}
